﻿@model IList<Shop.Home.Models.AnyBuyCar>
@{
    //购物车
    Layout = null;
}
@{double MoneyTotal = 0; }
@if (Model.Count != 0)
{
    <table class="table table-bordered table-striped table-hover">
        <tr>
            <td>序号</td>
            <td>商品名</td>
            <td>商品图片</td>
            <td>单价</td>
            <td>购买数量</td>
            <td>总价</td>
            <td>管理</td>
        </tr>
       
        @for (int i = 0; i < Model.Count; i++)
        {
            MoneyTotal += Model[i].MoneyTotal;
            <tr>
                <td>@(i + 1)</td>
                <td>@Model[i].WName</td>
                <td>
                    <img src="@Model[i].Url" style="width:40px;height:40px;" />
                </td>
                <td>@Model[i].UnitPrice 元</td>
                <td>@Model[i].BuyNum</td>
                <td>@Model[i].MoneyTotal 元</td>
                <td>
                    <input type="button" class="btn btn-default" value="删除" onclick="delshopcar('@Model[i].BCID')" />
                </td>
            </tr>
        }
    </table>
    <div class="page-header">
        <h1>
            <small>合计:@MoneyTotal 元</small>
            <input type="button" value="确定结算" class="btn btn-primary" style="float:right;" id="jiesuan" data-loading-text="加载中..."/>
        </h1>
    </div>
}
else
{
    <table class="table table-bordered table-striped table-hover">
        <tr>
            <td>序号</td>
            <td>商品名</td>
            <td>商品图片</td>
            <td>单价</td>
            <td>购买数量</td>
            <td>总价</td>
            <td>管理</td>
        </tr>
        <tr>
            <td colspan="7">空空如野啊</td>
        </tr>
    </table>
}
<script type="text/javascript">
    $("#jiesuan").click(function () {
        var $Btn = $(this).button('loading');
        setTimeout(function () { $Btn.button('reset'); }, 2000);
        $.ajax({
            cache: false,
            type: 'post',
            url: '@Url.Action("_Settlement")',
            data: { MoneyTotal: @(MoneyTotal)},
            dataType: 'text',
            success: function (data) {
                if (data == "User")
                {
                    alert("无效的用户状态，请重新登陆");
                    location.href = "@Url.Action("UsersLogin","User")";
                    return false;
                }
                else if (data != null)
                {
                    $("#Car").html(data);
                }
            },
            error: function () {
                alert("Ajax调用出错请与管理员联系");
            }
        });
    });
</script>